#region

using System.Text.Json;
using Vin.Tool.Core.JsonCategory;

#endregion

namespace Vin.Tool.Core.ExceptionCategory;

public class ExceptionTool
{
    public static string ExceptionMessage(Exception? ex)
    {
        if (ex == null) return string.Empty;
        var innerException = ex.InnerException != null
            ? JsonDocument.Parse(ExceptionMessage(ex.InnerException))
            : null;
        return new
        {
            ex.Message,
            ex.StackTrace,
            ex.Source,
            TargetSite = ex.TargetSite?.Name,
            InnerException = innerException?.RootElement
        }.ToCamelCaseJson();
    }
}